package gcu.module.property_apply.dao;

import gcu.module.property_apply.dao.mapper.ApplyMapper;
import gcu.module.property_apply.daomain.PropertyApply;
import gcu.util.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by haol on 2016/9/24.
 */
@Repository
public class ApplyDao {
      @Autowired
      private ApplyMapper mapper;

      private Logger logger = LoggerFactory.getLogger(ApplyDao.class);

      public void addApply(PropertyApply apply) {
            try {
                  mapper.addApply(apply);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }

      public void updateApply(PropertyApply apply) {
            try {
                  mapper.updateApply(apply);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }
      public void setApplyIsRead(int id) {
            try {
                  mapper.setApplyIsRead(id);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }
      public void deleteApply(int id) {
            try {
                  mapper.deleteApply(id);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
            }
      }

      public List<PropertyApply> queryApplyList(PropertyApply apply,Pager pager) {
            try {
                  int skip = (pager.getCurrentPage() - 1) * pager.getPageSize();
                  int pageSize = pager.getPageSize();
                  pager.setTotalSize(mapper.count(apply));
                  return mapper.query(apply,skip,pageSize);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }

      public PropertyApply queryApplyById(Integer id) {
            try {
                  return mapper.queryApplyById(id);
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }

      public List<PropertyApply> getNotHandle() {
            try {
                  return mapper.getNotHandle();
            } catch (Exception e) {
                  logger.error(e.getMessage());
                  e.printStackTrace();
                  return null;
            }
      }


}
